#include <bits/stdc++.h>
#define clr(a) memset(a, 0, sizeof a)
using namespace std;
typedef long long ll;
const int N = 4000*1000;
int tr[N][64], sz, cnt[N];
map<char, int> id;

void add(const string &s){
    int p = 0;
    ++cnt[0];
    for (char c:s){
        int &nx = tr[p][id[c]];
        if(!nx) nx = ++sz;
        p = nx;
        ++cnt[p];
    }
}

ll cmp(const string &s){
    ll ans = 0;
    ll p = 0;
    for (char c:s){
        ll nx = tr[p][id[c]];

        if(!nx) {ans += cnt[p]; break;}
        ans += (cnt[p]- cnt[nx]);
        ans += cnt[nx]*2;

        p = nx;
    }
    return ans;
}

int main() {
    ios::sync_with_stdio(false);cin.tie(nullptr);
    int tmp = 0;

    for (int i = 0; i < 10; ++i)  id[i+'0'] = ++tmp;
    for (int i = 0; i < 26; ++i)  id[i+'A'] = ++tmp;
    for (int i = 0; i < 26; ++i)  id[i+'a'] = ++tmp;
    id[0] = ++ tmp;
    int n;
    int T = 0;
    while (cin >> n && n){
        sz = 0;
        clr(tr), clr(cnt);

        ll ans = 0;
        string s;
        for (int i = 0; i < n; ++i) {
            cin >> s;
            s += '\0';
            ans += cmp(s);
            add(s);
        }
        cout << "Case " << ++T << ": " << ans << endl;
    }
    return 0;
}